<?php

namespace app\admin\model\outhouse;

use app\admin\model\information\Shelves;
use app\admin\model\information\Warehouse;
use think\Model;
use traits\model\SoftDelete;

class Tpdj extends Model
{

    use SoftDelete;

    

    // 表名
    protected $name = 'tpdj';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'datetime';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';


    public static  function  addData($params){
        $tpdjLog = [
            'code'=>$params['code'],
            'code_date' => isset($params['code_date'])?$params['code_date']:date('Y-m-d H:i:s'),
            'warehouse_id' => $params['warehouse_id'],
            'warehouse_change_id' => isset($params['warehouse_change_id'])?$params['warehouse_change_id']:$params['warehouse_id'],
            'warehouse_code' => $params['warehouse_code'],
            'warehouse_change_code' => isset($params['warehouse_change_code'])?$params['warehouse_change_code']:$params['warehouse_code'],
            'createtime'=>date('Y-m-d H:i:s'),
            //'updatetime'=>date('Y-m-d H:i:s'),
            'material_code' => $params['material_code']??'',
            'type'=>$params['type'],
            'remark' => isset($params['remark'])?$params['remark']:''
        ];
        self::insert($tpdjLog);
        return self::getLastInsID();

    }
    public function wareHouse(){
        return $this->hasOne('\app\admin\model\information\Warehouse','id','warehouse_id')->field('id,name');
    }
    public function changeWareHouse(){
        return $this->hasOne('\app\admin\model\information\Warehouse','id','warehouse_change_id')->field('id,name');
    }

    public function shelves(){
        return $this->hasOne('\app\common\model\Shelves','id','shelves_id')->field('id,name');
    }

    public function changeShelves(){
        return $this->hasOne('\app\common\model\Shelves','id','shelves_change_id')->field('id,name');
    }








}
